package org.jeecg.modules.rental.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.rental.entity.RentalCabinet;
import org.jeecg.modules.rental.mapper.RentalCabinetMapper;
import org.jeecg.modules.rental.service.IRentalCabinetService;
import org.springframework.stereotype.Service;

/**
 * @Description: 换电柜
 * @Author: sean
 * @Date:   2024-07-22
 * @Version: V1.0
 */
@Service
public class RentalCabinetServiceImpl extends ServiceImpl<RentalCabinetMapper, RentalCabinet> implements IRentalCabinetService {

    /*@Transactional
    public Result<Boolean> bind(String id, String deviceId) {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

        LambdaQueryWrapper<RentalCabinet> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RentalCabinet::getCcid,deviceId);

        List<RentalCabinet> dataList = baseMapper.selectList(queryWrapper);
        if (dataList.size()!=0){
            throw new JeecgBootException("物联网设备已经被绑定！请重新选择。");
        }
        RentalCabinet rentalCabinet = baseMapper.selectById(id);
        if (rentalCabinet==null){
            throw new JeecgBootException("设备不存在");
        }

        String nodeIdByDeviceId = baseMapper.getNodeIdByDeviceId(deviceId);
        if (nodeIdByDeviceId==null){
            throw new JeecgBootException("物联网设备不存在");
        }
        rentalCabinet.setIotId(deviceId);
        rentalCabinet.setUpdateTime(new Date());
        rentalCabinet.setUpdateBy(loginUser.getId());
        baseMapper.updateById(rentalCabinet);

        LambdaQueryWrapper<ChargeWarehouse> queryWarehouse = new LambdaQueryWrapper<>();
        queryWarehouse.eq(ChargeWarehouse::getCabinetId,id);
        List<RentalCabinet> warehouseList = chargeWarehouseMapper.selectList(queryWarehouse);
        RentalCabinet cdr =null;
        NumberFormat formatter =NumberFormat.getNumberInstance();
        for (ChargeWarehouse var:warehouseList){
            formatter.setMinimumIntegerDigits(2);
            formatter.setGroupingUsed(false);
            String warehouseNumber= formatter.format(var.getWarehouseNumber());
            cdr = new CreateDeviceReq();
            cdr.setDeviceName(chargeCabinet.getCabinetName()+"_"+var.getWarehouseNumber());
            cdr.setNodeId(nodeIdByDeviceId+"_"+warehouseNumber);
            // 仓控产品id
            cdr.setProductId("f80245c6-f3d6-430d-8e33-12617b4aa58e");
            String device = deviceClient.create(cdr);
            var.setIotId(device);
            chargeWarehouseMapper.updateById(var);
        }
        return Result.OK(true);
    }*/
}
